/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

enum BreakPointRange {
  xSmallLandscape,
  xSmallSquare,
  xSmallPortrait,
  smallLandscape,
  smallSquare,
  smallPortrait,
  mediumLandscape,
  mediumSquare,
  mediumPortrait,
  largeLandscape,
  largeSquare,
  largePortrait,
  xLargeLandscape,
  xLargeSquare,
  xLargePortrait,
}

enum VideoDirection {
  portrait, // 竖屏视频（高大>=宽）
  landscape, // 横屏视频（宽>高）
}

enum ScreenStatus {
  portraitFullScreen, // 竖屏全屏
  landscapeFullScreen, // 横向全屏
  normalScreen, // 正常屏幕
}

enum OrientationType {
  unKnown, // 未知
  portrait, // 仅竖屏向上
  autoRotationUnspecified, // 受控制中心的旋转开关控制，跟随传感器旋转，且可旋转方向受系统判定（如某种设备，无法旋转到反向竖屏）
  userRotationPortrait, // 临时竖屏向上，受控制中心的旋转开关控制，且可旋转方向受系统判断
  userRotationLandscape, // 临时横屏向左，受控制中心的旋转开关控制，且可旋转方向受系统判断
  userRotationLandscapeInverted, // 临时横屏向右，受控制中心的旋转开关控制，且可旋转方向受系统判断
}

class RotationRule {
  final List<BreakPointRange> breakPointRanges;
  final VideoDirection videoDirection;
  final ScreenStatus screenStatus;
  final Map<int, OrientationType> orientations;

  RotationRule({
    required this.breakPointRanges,
    required this.videoDirection,
    required this.screenStatus,
    required this.orientations,
  });
}

final Map<ScreenStatus, List<RotationRule>> rotationRulesMap = {
  ScreenStatus.normalScreen: [
    /// 断点区间：smallPortrait，mediumLandscape (如：直板机，purax折叠设备形态）
    /// 屏幕状态：非全屏
    /// 视频方向：竖向视频
    /// 旋转规则：竖屏显示
    RotationRule(
        breakPointRanges: [
          BreakPointRange.smallPortrait,
          BreakPointRange.mediumLandscape,
          BreakPointRange.smallSquare,
        ],
        videoDirection: VideoDirection.portrait,
        screenStatus: ScreenStatus.normalScreen,
        orientations: {
          0: OrientationType.portrait,
          1: OrientationType.portrait,
          2: OrientationType.portrait,
          3: OrientationType.portrait,
        }),

    /// 断点区间：smallPortrait，mediumLandscape (如：直板机）
    /// 屏幕状态：非全屏
    /// 视频方向：竖向视频
    /// 旋转规则：临时旋转到竖向，然后跟随设备旋转
    RotationRule(
        breakPointRanges: [
          BreakPointRange.smallPortrait,
          BreakPointRange.mediumLandscape,
        ],
        videoDirection: VideoDirection.landscape,
        screenStatus: ScreenStatus.normalScreen,
        orientations: {
          0: OrientationType.userRotationPortrait,
          1: OrientationType.userRotationPortrait,
          2: OrientationType.userRotationPortrait,
          3: OrientationType.userRotationPortrait,
        }),

    /// 断点区间：smallSquare (如：purax折叠设备形态）
    /// 屏幕状态：非全屏
    /// 视频方向：横向视频
    /// 旋转规则：竖屏显示
    RotationRule(
        breakPointRanges: [
          BreakPointRange.smallSquare,
        ],
        videoDirection: VideoDirection.landscape,
        screenStatus: ScreenStatus.normalScreen,
        orientations: {
          0: OrientationType.portrait,
          1: OrientationType.portrait,
          2: OrientationType.portrait,
          3: OrientationType.portrait,
        }),

    /// 断点区间：mediumPortrait，mediumSquare，largePortrait，largeSquare，largeLandscape，xLargeLandscape (如：平板等大屏设备）
    /// 屏幕状态：非全屏
    /// 视频方向：竖向视频
    /// 旋转规则：可自由旋转
    RotationRule(
        breakPointRanges: [
          BreakPointRange.mediumPortrait,
          BreakPointRange.mediumSquare,
          BreakPointRange.largeLandscape,
          BreakPointRange.largeSquare,
          BreakPointRange.largePortrait,
          BreakPointRange.xLargeLandscape,
        ],
        videoDirection: VideoDirection.portrait,
        screenStatus: ScreenStatus.normalScreen,
        orientations: {
          0: OrientationType.autoRotationUnspecified,
          1: OrientationType.autoRotationUnspecified,
          2: OrientationType.autoRotationUnspecified,
          3: OrientationType.autoRotationUnspecified,
        }),

    /// 断点区间：mediumPortrait，mediumSquare，largePortrait，largeSquare，largeLandscape，xLargeLandscape (如：平板等大屏设备）
    /// 屏幕状态：非全屏
    /// 视频方向：横向视频
    /// 旋转规则：可自由旋转
    RotationRule(
        breakPointRanges: [
          BreakPointRange.mediumPortrait,
          BreakPointRange.mediumSquare,
          BreakPointRange.largeLandscape,
          BreakPointRange.largeSquare,
          BreakPointRange.largePortrait,
          BreakPointRange.xLargeLandscape,
        ],
        videoDirection: VideoDirection.landscape,
        screenStatus: ScreenStatus.normalScreen,
        orientations: {
          0: OrientationType.autoRotationUnspecified,
          1: OrientationType.autoRotationUnspecified,
          2: OrientationType.autoRotationUnspecified,
          3: OrientationType.autoRotationUnspecified,
        }),
  ],

  /// 竖向全屏
  ScreenStatus.portraitFullScreen: [
    /// 断点区间：smallPortrait，mediumLandscape，smallSquare (如：直板机，purax折叠设备形态）
    /// 屏幕状态：竖向
    /// 视频方向：竖向视频
    /// 旋转规则：竖屏显示
    RotationRule(
        breakPointRanges: [
          BreakPointRange.smallPortrait,
          BreakPointRange.mediumLandscape,
          BreakPointRange.smallSquare,
        ],
        videoDirection: VideoDirection.portrait,
        screenStatus: ScreenStatus.portraitFullScreen,
        orientations: {
          0: OrientationType.portrait,
          1: OrientationType.portrait,
          2: OrientationType.portrait,
          3: OrientationType.portrait,
        }),

    /// 断点区间：mediumPortrait，mediumSquare，largePortrait，largeSquare，largeLandscape，xLargeLandscape (如：平板等大屏设备）
    /// 屏幕状态：竖向全屏
    /// 视频方向：竖向视频
    /// 旋转规则：自由旋转
    RotationRule(
        breakPointRanges: [
          BreakPointRange.mediumPortrait,
          BreakPointRange.mediumSquare,
          BreakPointRange.largePortrait,
          BreakPointRange.largeSquare,
          BreakPointRange.largeLandscape,
          BreakPointRange.xLargeLandscape,
        ],
        videoDirection: VideoDirection.portrait,
        screenStatus: ScreenStatus.portraitFullScreen,
        orientations: {
          0: OrientationType.autoRotationUnspecified,
          1: OrientationType.autoRotationUnspecified,
          2: OrientationType.autoRotationUnspecified,
          3: OrientationType.autoRotationUnspecified,
        }),
  ],

  /// 横向全屏
  ScreenStatus.landscapeFullScreen: [
    /// 断点区间：smallPortrait，mediumLandscape (如：直板机）
    /// 屏幕状态：横向全屏
    /// 视频方向：横向视频
    /// 旋转规则：竖屏时，临时旋转到反向横向，且随设备旋转方向旋转
    RotationRule(
        breakPointRanges: [
          BreakPointRange.smallPortrait,
          BreakPointRange.mediumLandscape
        ],
        videoDirection: VideoDirection.landscape,
        screenStatus: ScreenStatus.landscapeFullScreen,
        orientations: {
          0: OrientationType.userRotationLandscapeInverted,
          1: OrientationType.userRotationLandscapeInverted,
          2: OrientationType.userRotationLandscape,
          3: OrientationType.userRotationLandscape,
        }),

    /// 断点区间：smallSquare (如：purax折叠设备形态）
    /// 屏幕状态：横向全屏
    /// 视频方向：横向视频
    /// 旋转规则：竖屏显示
    RotationRule(
        breakPointRanges: [
          BreakPointRange.smallSquare,
        ],
        videoDirection: VideoDirection.landscape,
        screenStatus: ScreenStatus.landscapeFullScreen,
        orientations: {
          0: OrientationType.portrait,
          1: OrientationType.portrait,
          2: OrientationType.portrait,
          3: OrientationType.portrait,
        }),

    /// 断点区间：mediumPortrait，mediumSquare，largePortrait，largeSquare，largeLandscape，xLargeLandscape (如：平板等大屏设备）
    /// 屏幕状态：横向全屏
    /// 视频方向：横向视频
    /// 旋转规则：自由旋转
    RotationRule(
        breakPointRanges: [
          BreakPointRange.mediumPortrait,
          BreakPointRange.mediumSquare,
          BreakPointRange.largePortrait,
          BreakPointRange.largeSquare,
          BreakPointRange.largeLandscape,
          BreakPointRange.xLargeLandscape
        ],
        videoDirection: VideoDirection.landscape,
        screenStatus: ScreenStatus.landscapeFullScreen,
        orientations: {
          0: OrientationType.autoRotationUnspecified,
          1: OrientationType.autoRotationUnspecified,
          2: OrientationType.autoRotationUnspecified,
          3: OrientationType.autoRotationUnspecified,
        }),
  ],
};
